﻿Imports System.ComponentModel

Namespace Audio.Devices
	''' <summary>
	''' A list of channel types a channel can be. This dictates how many channel numbers a device returns.
	''' </summary>
	''' <remarks></remarks>
	<Serializable> Public Enum DeviceChannelType As Integer
		Stereo = 0
	End Enum

	''' <summary>
	''' Information about a specific audio device channel.
	''' </summary>
	''' <remarks></remarks>
	<Serializable> Public Class DeviceChannel
		Implements INotifyPropertyChanged
		Public Sub RaisePropertyChanged(PropertyName As String)
			RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PropertyName"))
		End Sub



		Public Sub New()
		End Sub

		Public Sub New(CID As Integer, Typ As DeviceChannelType, Def As Boolean)
			ChannelID = CID
			ChannelType = Typ
			IsDefault = Def
		End Sub

		Public Overrides Function Equals(obj As Object) As Boolean
			If obj.GetType() IsNot GetType(DeviceChannel) Then
				Return False
			Else
				With CType(obj, DeviceChannel)
					If ChannelID = .ChannelID AndAlso ChannelType = .ChannelType AndAlso IsDefault = .IsDefault AndAlso Name = .Name Then
						Return True
					Else
						Return False
					End If
				End With
			End If

		End Function



		''' <summary>
		''' The type of channel this is. Defaults to stereo.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property ChannelType As DeviceChannelType
			Get
				Return ChannelTypeProperty
			End Get
			Set(value As DeviceChannelType)
				ChannelTypeProperty = value
				RaisePropertyChanged("ChannelType")
			End Set
		End Property
		Private ChannelTypeProperty As DeviceChannelType = DeviceChannelType.Stereo


		''' <summary>
		''' The ID of the channel.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks>Note that device channels should NOT share ID numbers and should be offset by the number of device channels an individual channel returns. For example, two stereo channels would be ID:0 and ID:2</remarks>
		Public Property ChannelID As Integer
			Get
				Return ChannelIDProperty
			End Get
			Set(value As Integer)
				ChannelIDProperty = value
				RaisePropertyChanged("ChannelID")
			End Set
		End Property
		Private ChannelIDProperty As Integer = -1


		''' <summary>
		''' Returns true if this channel should be included by default when creating new cues.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsDefault As Boolean
			Get
				Return IsDefaultProperty
			End Get
			Set(value As Boolean)
				IsDefaultProperty = value
				RaisePropertyChanged("IsDefault")
			End Set
		End Property
		Private IsDefaultProperty As Boolean = False

		''' <summary>
		''' Returns true if this channel is enabled.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property IsEnabled As Boolean
			Get
				Return IsEnabledProperty
			End Get
			Set(value As Boolean)
				IsEnabledProperty = value
				RaisePropertyChanged("IsEnabled")
			End Set
		End Property
		Private IsEnabledProperty As Boolean = False

		Public Property Name As String
			Get
				Return NameProperty
			End Get
			Set(value As String)
				NameProperty = value
				RaisePropertyChanged("Name")
			End Set
		End Property
		Private NameProperty As String = "Audio Channel"


		''' <summary>
		''' Returns the IDs of individual channels this channel contains. 
		''' </summary>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Function GetChannelNumbers() As Integer()
			If ChannelID = -1 Then
				Return Nothing
				'ElseIf ChannelType = DeviceChannelType.Mono Then
				'	Dim ch(0) As Integer
				'	ch(0) = ChannelID
				'	Return ch
			ElseIf ChannelType = DeviceChannelType.Stereo Then
				Dim ch(1) As Integer
				ch(0) = ChannelID
				ch(1) = ChannelID + 1
				Return ch
			Else
				Return Nothing
			End If
		End Function

		''' <summary>
		''' Gets the total number of channels this device channel contains. (ie. Stereo contains 2)
		''' </summary>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Function GetChannelCount() As Integer
			If ChannelType = DeviceChannelType.Stereo Then
				Return 2
			Else
				Return 0
			End If
		End Function

		<NonSerialized> Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
	End Class
End Namespace